package de.unibi.comet.ac;

import java.util.Iterator;

public abstract class AbstractSuffixStructureNode implements SuffixStructureNode {

	public String toPsTricks() {
		Iterator<SuffixStructureNode> iter = childrenIterator();
		StringBuffer s = new StringBuffer();
		if (iter.hasNext()) {
			s.append("\\pstree[]{");
			if (!isSuffix()) s.append("\\psset{linestyle=dashed}");
			s.append(String.format("\\Tcircle{%d,%s}}{", getNumber(), getText()));
			while (iter.hasNext()) {
				SuffixStructureNode child = iter.next();
				String child_str = child.toPsTricks();
				int k = child_str.indexOf("\\Tcircle");
				if (k>=0) k=child_str.indexOf("}",k);
				if (k>=0){
					s.append(child_str.substring(0, k+1));
					s.append("\\tlput{"+child.getEdgeText()+"}");
					s.append(child_str.substring(k+1));
				}
			}
		} else {
			if (!isSuffix()) s.append("\\psset{linestyle=dashed}");
			s.append(String.format("\\Tcircle{%d,%s", getNumber(), getText()));
		}
		s.append("}");
		return s.toString();
	}
}
